 package com.oanda.blackberry.restapi;
 
 import net.rim.device.api.util.MathUtilities;
 import net.rim.device.api.util.Persistable;
 
 public class Symbol
   implements Persistable
 {
   String symbol;
   int precision;
   double piploc;
   boolean active;
   static String defaultList = "AUD/JPY, AUD/USD, EUR/CHF, EUR/GBP, EUR/JPY, EUR/USD, GBP/JPY, GBP/USD, USD/CAD, USD/CHF, USD/JPY, XAU/USD";
 
   static String defaultFormattedList = "AUD/JPY,AUD/USD,EUR/CHF,EUR/GBP,EUR/JPY,EUR/USD,GBP/JPY,GBP/USD,USD/CAD,USD/CHF,USD/JPY,XAU/USD";
 
   int rank = 0;
 
   public Symbol(String symbol, int precision, double piploc, boolean active) {
     this.symbol = symbol;
     this.precision = precision;
     this.piploc = piploc;
     this.active = active;
   }
 
   public double getPiploc() {
     return this.piploc;
   }
 
   public int getPrecision() {
     return this.precision;
   }
 
   public String getSymbol() {
     return this.symbol;
   }
 
   public boolean isActive() {
     return this.active;
   }
 
   public void setActive(boolean active) {
     this.active = active;
   }
 
   public int getPipetteLength()
   {
     try
     {
       double p = 0.0D;
       if (this.precision == 0) {
         return String.valueOf(new Double(this.piploc).intValue()).length();
       }
       if (this.precision == 1) {
         return String.valueOf(new Double(p).intValue()).length();
       }
       p = this.precision / this.piploc / this.precision / 10.0D;
 
       p = MathUtilities.round(p);
 
       return this.precision - String.valueOf(new Double(p).intValue()).length();
     } catch (NumberFormatException ne) {
       return 0; } catch (IndexOutOfBoundsException i) {
     }
     return 0;
   }
 
   public static boolean autoCheckActiveDefaultList(String symbolName)
   {
     return (symbolName != null) && (symbolName.length() > 0) && 
       (defaultList.indexOf(symbolName) > -1);
   }
 
   public static boolean isPopularSymbol(String symbolName)
   {
     return (symbolName != null) && (symbolName.length() > 0) && 
       (defaultList.indexOf(symbolName) > -1);
   }
 
   public static String getDefaultSymbolsList()
   {
     return defaultFormattedList;
   }
 
   private void setRank(String symbolName) {
     if (symbolName.indexOf(defaultFormattedList) > -1)
       if (symbolName.equals("EUR/USD")) this.rank = 12;
       else if (symbolName.equals("GBP/USD")) this.rank = 11;
       else if (symbolName.equals("USD/JPY")) this.rank = 10;
       else if (symbolName.equals("AUD/USD")) this.rank = 9;
       else if (symbolName.equals("EUR/JPY")) this.rank = 8;
       else if (symbolName.equals("GBP/JPY")) this.rank = 7;
       else if (symbolName.equals("XAU/USD")) this.rank = 6;
       else if (symbolName.equals("USD/CHF")) this.rank = 5;
       else if (symbolName.equals("AUD/JPY")) this.rank = 4;
       else if (symbolName.equals("EUR/GBP")) this.rank = 3;
       else if (symbolName.equals("USD/CAD")) this.rank = 2;
       else if (symbolName.equals("EUR/CHF")) this.rank = 1;
   }
 
   public int getRank()
   {
     return this.rank;
   }
 
   public double getPippettes(double pips) {
     double pippettes = 0.0D;
     if ((this.piploc > 0.0D) && (this.piploc < 1.0D))
       pippettes = pips * MathUtilities.pow(10.0D, getPipetteLength());
     else if (this.piploc >= 1.0D)
       pippettes = pips * 10.0D;
     else if (this.piploc == 0.0D) {
       pippettes = pips;
     }
     return pippettes;
   }
 
   public double getPips(double pippettes) {
     double pips = 0.0D;
     if ((this.piploc > 0.0D) && (this.piploc < 1.0D)) {
       pips = pippettes / MathUtilities.pow(10.0D, getPipetteLength());
     } else {
       if (this.piploc >= 1.0D)
         return pippettes / 10.0D;
       if (this.piploc == 0.0D)
         return pippettes;
     }
     return pips;
   }
}

